<?php if (isset($project)) {  
    
//             $total=$project['Project']['duration'];$acum=0;
//           for($i=0;$i<count($project['Stories']);$i++){
//                $s=',';
//                if ($i==0) 
//                    echo  '[0,'.($total).']';
//                
//                if ( $project['Stories'][$i]['Story']['state']==3){
//                    $total-=$project['Stories'][$i]['Story']['duration'];
//                    $acum+=$project['Stories'][$i]['Story']['duration'];
//                    echo  $s.$project['Stories'][$i]['Story']['summary'].'-'.'['.($acum).','.($total).']';
//                }
//                
//            }
//            echo '<br/>';
//            $total=$project['Project']['duration'];$acum=0;
//           for($i=0;$i<count($project['Stories']);$i++){
//               $s=',';
//                if ($i==0) 
//                    echo  '[0,'.($total).']';
//                $total-=$project['Stories'][$i]['Story']['points'];
//                $acum+=$project['Stories'][$i]['Story']['points'];
//                echo  $s.'['.($acum).','.($total).']';
//                
//            }
     
//    echo $project['Project']['points'].'<br/>';
//    echo $project['Project']['duration'].'<br/>';
//     echo $project['Project']['end'].'/'.strtotime($project['Project']['end']).'<br/>';
//     echo $project['Project']['begin'].'/'.strtotime($project['Project']['begin']).'<br/>';
//     echo 'RESTAAA'.'/'.(strtotime($project['Project']['end'])-strtotime($project['Project']['begin'])).'<br/>';
//     //echo date('l jS \of F Y h:i:s A').(strtotime($project['Project']['end'])-strtotime($project['Project']['begin']));
//     echo strftime("%Y%m%d",strtotime($project['Project']['end'])).'<br/>';
//     echo strftime("%Y%m%d",strtotime($project['Project']['begin'])).'<br/>';
//     echo (strftime("%Y%m%d",strtotime($project['Project']['end']))-strftime("%m%d%Y",strtotime($project['Project']['begin']))).'<br/>';
     
//     
//    $events = array( 
//    '2012' => array( 
//        '07' => array( 
//            '5' => 'My Birthday', 
//            '8' => 'Joe\'s Birthday', 
//            '10' => array('Vern\'s Birthday','Columbus Day') 
//        ) 
//    ) 
//    ); 
//echo $this->Calendar->draw(array('events' => $events)); 
//    echo $this->Calendar->draw();
// 
    ?>

    <div class="row-fluid ">
        <div class="span12">
            <div class="span9">
                <h1><?php echo '<h1>Proyecto :' ;

                    echo $this->Html->link(h($project['Project']['name']),'edit/'.$project['Project']['id']).'</h1>';
                ?></h1>

                <p><small>Created: <?php echo $project['Project']['created']; ?></small></p>

                <p><?php echo h($project['Project']['description']); ?></p>
            </div> 
            <div class="span3" align="right">
                <?php 
                echo $this->Html->link('Backlog',array('action'=>'backlog',$project['Project']['id']),array('class'=>'btn btn-primary')); 
                ?>
            </div>
        </div>
    </div>
    
    
    
    <div class="row-fluid " style=" margin-bottom: 20px;  margin-top: 20px;">
        <div class="span12">
            <div class="span2"></div>
            <div class="span3">
                <div class="bs-docs-example">
                    <div class="lead" align="center">
                        Total de Historias<br/> 
                        <?php echo count($project['Story'])?>
                    </div>
                 </div>
            </div>

            <div class="span3">
                <div class="bs-docs-example">
                    <div class="lead" align="center">
                        Historias Terminadas<br/> 
                        <?php echo $project['Project']['terminadas']?>
                    </div>
                </div>

            </div>
            <div class="span3">
                <div class="bs-docs-example">
                    <div class="lead" align="center">
                        Historias En Progreso<br/> 
                        <?php echo $project['Project']['enProgreso']?>
                    </div>
                </div>
            </div>
            <div class="span1"></div>
        </div>
    </div>
    <div class="row-fluid " id="container">
        <h6>Gráfico Burn Down</h6>
        <div class="span12" id="container2" style="height: 200px;"></div>
    </div>
    
    
  
    <?php echo $this->Javascript->link('../css/flotr2/flotr2.min.js');?>
    <script type="text/javascript">
      (function () {

        var
          
          container = document.getElementById('container2'),
          WidthPrin = document.getElementById('container').offsetWidth,
           estimated = [<?php 
           $total=$project['Project']['duration'];$acum=0;
           for($i=0;$i<count($project['Stories']);$i++){
               $s=',';
                if ($i==0) 
                    echo  '[0,'.($total).']';
                $total-=$project['Stories'][$i]['Story']['points'];
                $acum+=$project['Stories'][$i]['Story']['points'];
                echo  $s.'['.($acum).','.($total).']';
                
            }
            
           ?>], // First data series
           real = [<?php 
           $total=$project['Project']['duration'];$acum=0;
           for($i=0;$i<count($project['Stories']);$i++){
                $s=',';
                if ($i==0) 
                    echo  '[0,'.($total).']';
                
                if ( $project['Stories'][$i]['Story']['state']==3){
                    $total-=$project['Stories'][$i]['Story']['points'];
                    $acum+=$project['Stories'][$i]['Story']['duration'];
                    echo  $s.'['.($acum).','.($total).']';
                }
                
            }
            
           ?>],                                // Second data series
           i, graph;

        // Generate first data set
//        for (i = 0; i < 14; i += 0.5) {
//            d2.push([i, Math.sin(i)]);
//        }
        container.style.width = WidthPrin;
        // Draw Graph
        graph = Flotr.draw(container, [ 
            { data : estimated, label : 'Ideal Remaining Effort', lines : { show : true }, points : { show : true } },
            { data : real, label : 'Actual Remaining Effort', lines : { show : true }, points : { show : true } }
            ], {
            /*xaxis: {
            minorTickFreq: 4
            },*/ 
            grid: {
                verticalLines: true
            },
            legend : {
                position : 'ne',
                backgroundColor : '#D2E8FF'
            },
            title : 'Gráfico Burn Down'
        });
      })();
    </script>





    <br/>
    
    <div class="row-fluid ">
        <div class="span12">
            <div class="span8">
                <h3>Equipos en el proyecto: </h3>
            </div>
            <div class="span4" align="right">
                <a href="<?php echo $this->base ;?>/teams/add/<?php echo $project['Project']['id']; ?>" class="btn btn-small btn-inverse"><i class="icon-plus-sign icon-white"></i> Nuevo</a>
            </div>
        </div>
    </div>
    <br/>

    

    <?php if (count($project['Team'])>0) {
        $teams=$project['Team'];
        ?> 
    <table class="table table-bordered">
            <tr>
                <th>Nombre</th>
                <th>Detales</th>
            </tr>
            <?php for ($i = 0; $i < count($teams); $i++ ){ ?>
                <tr>
                    <td> <?php
                        echo $this->Html->link($teams[$i]['ProjectTeam']['name'],array('controller'=>'teams','action'=>'view',$teams[$i]['id'])); 
                        ?>
                    </td>
                    <td>
                        <?php echo h($teams[$i]['ProjectTeam']['detail']);?>
                        
                    </td>
                </tr>
            <?php } ?>
    </table>
    <?php } else {?>
        <div class="alert alert-info">
            No se han encontrado Equipos.
        </div>
    <?php } ?>


 
    <div class="row-fluid ">
    <?php echo $this->Form->create('ProjectTeam',array('url'=> '../teams/addToProject/'.$project['Project']['id'].'/1','class'=>'form-inline','inputDefaults' => array('label' => false ,'div' => false,'class'=>'input')));

            $arrOptions=array();
            for ($i=0;$i<count($teamsOrg);$i++){
                $idT=$teamsOrg[$i]['Team']['id'];
                $nameT=$teamsOrg[$i]['Team']['name'];
                $arrOptions[$idT]=$nameT;
            }
            ?>
            <span class="help-inline"><h4>Añadir un equipo de la organización: </h4></span>
            <?php
            echo $this->Form->input('team_id', array(
                        'options' => $arrOptions,'class'=>'chzn-select',
                        'empty' => '(choose one)'
                    ));
            echo "    ";

            echo $this->Form->hidden('project_id',array('value'=>$project['Project']['id']));
            ?>
            
            <button type="submit" class="btn" >Agregar</button>
            <?php echo '</form>'; ?>

     </div>
    
<?php } else {?>
    <br/>
    <div class="alert alert-info">
        Error de acceso.
    </div>
<?php }?>



    